#include "stdafx.h"
#include "ScreenQuad.h"
#include "VertexFormats.h"
#include "VertexBuffer.h"
#include "ShaderContainer.h"
#include "GraphicsManager.h"
#include "../EdgeContent/ContentManager.h"

using namespace VertexFormats;

ScreenQuad::ScreenQuad(void)
{
	Init();
}

ScreenQuad::ScreenQuad(Box2D& bounds)
{
	Init();
	gShaderInfo.region = bounds;
	gShaderInfo.texRect = { 0.f, 1.f, 0.f, 1.f };
	
}

/*virtual*/ ScreenQuad::~ScreenQuad(void)
{
	for (unsigned int i = 0; i < 4; i++)
		if (srvs[i])
			delete srvs[i];

	delete vertexBuffer;
	delete shaderContainer;
	delete gShaderUiBuffer;
	delete pShaderUiBuffer;
}

void ScreenQuad::Init(void)
{
	memset(srvs, 0, sizeof(srvs));
	// create vertex buffer
	Vertex vBuffer;
	unsigned int iBuffer;
	vertexBuffer = new VertexBuffer(&vBuffer, &iBuffer, 1, 1, VERTEX_TYPE_POSITION);
	vertexBuffer->setTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

	// load shaders
	shaderContainer = ContentManager::GetInstance()->LoadShaderPair("Basic2DRenderVShader.cso", "Basic2DRenderPShader.cso", "Basic2DRenderGShader.cso");

	// setup buffers
	gShaderUiBuffer = new ConstantBuffer<VRAM_VS_UI>(&gShaderInfo, { SHADER_INDEX_GEOMETRY_SHADER, 0 });
	pShaderUiBuffer = new ConstantBuffer < VRAM_PS_UI >(&pShaderInfo, { SHADER_INDEX_PIXEL_SHADER, 0 });
	pShaderInfo.use_texture = true;
	pShaderInfo.color = vector_4::white;
}

void ScreenQuad::Draw(void)
{
	//pShaderInfo.use_texture = true;
	gShaderUiBuffer->Bind();
	pShaderUiBuffer->Bind();
	GraphicsManager::GetInstance()->Draw(this);
}